<!---
Copyright: (c) 2006 The MachBlog Authors
Authors: Matt Woodward (mpwoodward@gmail.com) & Peter J. Farrell (pjf@maestropublishing.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License.

$Id:  $

Notes:
--->
<cfcomponent displayname="Application CFC" output="true" extends="MachII.mach-ii">

	<cfprocessingdirective pageencoding="utf-8" />
	
	<cfscript>
		// application settings
		this.name = "machblog";
		this.clientmanagement = false;
		this.sessionmanagement = true;
		this.sessiontimeout = createTimeSpan(0,20,0,0);
		this.setclientcookies = false;
		
		// mach-ii settings
		MACHII_CONFIG_PATH = ExpandPath("./config/mach-ii.xml.cfm");
		MACHII_APP_KEY = GetFileFromPath(ExpandPath("."));
		MACHII_CONFIG_MODE = 0;
		MACHII_VALIDATE_XML = false;
		MACHII_DTD_PATH = ExpandPath("/MachII/mach-ii_1_5_0.dtd");
	</cfscript>

	<cffunction name="onApplicationStart" output="false" returntype="boolean">
		<cfset loadFramework() />
		<cfreturn true />
	</cffunction>

	<cffunction name="onRequestStart" output="true" returntype="boolean">
		<cfargument name="targetPage" type="string" required="true" />

		<cfset request.self = "index.cfm" />
		<cfset setEncoding("form", "utf-8") />
		<cfset setEncoding("url", "utf-8") />
		
		<!--- handle initialization and FCKeditor settings --->
		<cfif Not StructKeyExists(Application, "init") OR Not Application.init OR (StructKeyExists(url, "init") AND url.init EQ "yes")>
			<cflock scope="Application" type="exclusive" timeout="10" throwontimeout="yes">
				<cfset Application.init = true />
				<cfset Application.FCKeditor = StructNew() />
				<cfset Application.FCKeditor.userFilesPath = "/machblog/uploads/" />
			</cflock>
	
			<cfset MACHII_CONFIG_MODE = 1 />
			<cfsetting requesttimeout="120" />
			<cfobjectcache action="CLEAR" />
		<cfelse>
			<cfset MACHII_CONFIG_MODE = 0 />
		</cfif>
		
		<!--- security for fckeditor --->
		<cfif find("FCKeditor", CGI.SCRIPT_NAME)>
			<cfif not structKeyExists(session, "user") or session.user.getUserId() eq "">
				You are not logged in.
				<cfabort />
			</cfif>
		</cfif>

		<!--- set per-session cookies if not using j2ee session management --->
		<cfif structKeyExists(session, "cfid") and (not structKeyExists(cookie, "cfid") or not structKeyExists(cookie, "cftoken"))>
			<cfcookie name="cfid" value="#session.cfid#" />
			<cfcookie name="cftoken" value="#session.cftoken#" />
		</cfif>

		<!--- handle the request --->
		<cfif findNoCase("index.cfm", listLast(arguments.targetPage, "/"))>
			<cfset handleRequest() />
		</cfif>
		
		<cfreturn true />
	</cffunction>

</cfcomponent>